<%--
  Created by IntelliJ IDEA.
  User: 12
  Date: 2023/3/11
  Time: 8:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--1. 引入jquery--%>
<script src="/webjars/jquery/3.6.1/jquery.min.js"></script>
<%--2. 引入bootstrap--%>
<link rel="stylesheet" href="/webjars/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="/webjars/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
    .container{
        width: 50%;
    }
</style>
<script>
    //1. 取得员工id
    $(function () {
        let eid = $("#eid").val()
        /*console.log("sid:",sid)*/
        if(eid){
            $("#title").html("修改学生")
        }else{
            $("#title").html("添加学生")
        }
    })
    //2. 保存员工
    function save() {
        let eid = $("#eid").val()
        //2.1 确定url地址
        let url = "/emp/add.do"
        if(eid){
            url = "/emp/update.do"
        }
        //2.2 为表单的action属性赋值
        document.forms[0].action = url
        //2.3 提交表单
        document.forms[0].submit();
    }
</script>
<html>
<head>
    <title>添加员工</title>
</head>
<body>
    <div class="container">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <h3 id="title">添加员工</h3>
                </h3>
            </div>
            <div class="panel-body">
                <form class="form-horizontal"  method="post">
                    <%--隐藏表单域，为了给修改员工时能够找到对应的员工--%>
                    <input type="hidden" name="eid" id="eid" value="${emp.eid}">
                    <div class="form-group">
                        <label for="ename" class="col-sm-2 control-label">员工姓名</label>
                        <div class="col-sm-10">
                            <%--value是为了在修改学生信息的时候能够得到对应的学生信息--%>
                            <input type="text" class="form-control" id="ename" name="ename" value="${emp.ename}" placeholder="请输入姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="bdate" class="col-sm-2 control-label">入职日期</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="bdate" name="bdate" value="${emp.bdate}" placeholder="请输入日期">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-2 control-label">员工性别</label>
                        <div class="col-sm-10">
                            <div class="radio">
                                <label>
                                    <input type="radio" name="sex" id="sex1" value="男" ${emp.sex == '男' ? 'checked' : ''}>男
                                </label>
                                <label>
                                    <input type="radio" name="sex" id="sex2" value="女" ${emp.sex == '女' ? 'checked' : ''}>女
                                </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="city" class="col-sm-2 control-label">员工籍贯</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="city" value="${emp.city}" name="city" placeholder="请输入籍贯">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="did" class="col-sm-2 control-label">所在部门</label>
                        <div class="col-sm-10">
                            <select class="form-control" name="did" id="did">
                                <c:forEach items="${dept}" var="d">
                                    <option value="${d.did}" ${d.did == emp.did ? "selected" : ''}>${d.dname}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-primary btn-block" onclick="save()">保存</button>
                        </div>
                    </div>
                </form>
            </div>
            <div class="panel-footer text-right">
                考试
            </div>
        </div>
    </div>
</body>
</html>
